package translation;

import java.util.ArrayList;
import java.util.List;

import translation.FilteredSourceFieldType.VariableBinding;

/**
 * Variable Binding class
 * To add an element use the "addExplicitPrefixBinding" 
 * method instead of getExplicitPrefixBinding().add(string)
 * 
 * @author ndemetriou
 *
 */
public class VarBinding{
	private String explicitBinding = null;
	private String listBinding = null;
	private List<String> explicitPrefixBinding = null;
	private List<String> explicitPostfixBinding = null;

	public VarBinding(){}

	//Explicit Binding
	public String getExplicitBinding() {
		return explicitBinding;
	}
	public void setExplicitBinding(String explicitBinding) {
		this.explicitBinding = explicitBinding;
	}

	//Prefix Binding
	public List<String> getExplicitPrefixBinding() {
		return explicitPrefixBinding;
	}
	public void addAllExplicitPrefixBinding(List<String> list){
		if(list != null && list.size() > 0){				
			if(explicitPrefixBinding == null)
				explicitPrefixBinding = new ArrayList<String>();

			explicitPrefixBinding.addAll(list);
		}
	}
	public void addExplicitPrefixBinding(String variable){
		if(explicitPrefixBinding == null)
			explicitPrefixBinding = new ArrayList<String>();

		explicitPrefixBinding.add(0, variable);
	}

	//Postfix Binding
	public List<String> getExplicitPostfixBinding() {
		return explicitPostfixBinding;
	}
	public void addAllExplicitPostfixBinding(List<String> list){
		if(list != null && list.size() > 0){
			if(explicitPostfixBinding == null)
				explicitPostfixBinding = new ArrayList<String>();

			explicitPostfixBinding.addAll(list);
		}
	}
	public void addExplicitPostfixBinding(String variable){
		if(explicitPostfixBinding == null)
			explicitPostfixBinding = new ArrayList<String>();

		explicitPostfixBinding.add(0, variable);
	}

	//List Binding
	public String getListBinding() {
		return listBinding;
	}
	public void setListBinding(String listBinding) {
		this.listBinding = listBinding;
	}	
	
	/**
	 * Converts and return the VarBinding to a Variable Binding of the translation package
	 * @return The Variable Binding representation of this class
	 */
	public VariableBinding toVariableBinding(){
		VariableBinding vb = new VariableBinding();
		vb.setExplicitBinding(explicitBinding);
		vb.setListBinding(listBinding);
		if(explicitPrefixBinding != null)
			for(String s : explicitPrefixBinding)
				vb.getExplicitPrefixBinding().add(s);
		
		if(explicitPostfixBinding != null)
			for(String s : explicitPostfixBinding)
				vb.getExplicitPostfixBinding().add(s);
		
		return vb;
	}
}